<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('申请寄养')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-user-applyfost">
		<div class="form-group">
			<label class="col-sm-3 control-label">宠物名称：</label>
			<div class="col-sm-8">
				<input type="text" name="name" class="form-control" placeholder="请输入宠物名称">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">宠物类型：</label>
			<div class="col-sm-8">
				<input type="text" name="type" class="form-control" placeholder="请输入宠物类型">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">联系电话：</label>
			<div class="col-sm-8">
				<input type="text" name="phone" class="form-control" placeholder="请输入联系电话">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">性别：</label>
			<div class="col-sm-8">
				<select id="sex" name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_pet_sex')}">
					<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">备注：</label>
			<div class="col-sm-8">
				<textarea id="remark" type="text" name="remark" class="form-control" placeholder="请输入备注"></textarea>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">宠物照片：</label>
			<input id="filePath" name="filePath" class="form-control" type="file" style="padding: 3px 6px;
                padding-left: 10px;
                border: 1px solid #E7EAEC;
                width: 230px;
                height: 25px;
                line-height: 25px;
                border-left: 3px solid #3FB7EB;
                background: #FAFAFB;
                border-radius: 2px;
                 border: 0px;" >
		</div>
	</form>
	<div class="row">
		<div class="col-sm-offset-5 col-sm-10">
			<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
			<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
	function submitHandler() {
			add();
	}
	function add() {
		var name = $("input[name='name']").val();
		var type = $("input[name='type']").val();
		var phone = $("input[name='phone']").val();
		var sex = $('#sex option:selected').val();
		var remark = $('#remark').val();
		var formData = new FormData();
		if ($('#filePath')[0].files[0] == null) {
			$.modal.alertWarning("请先选择文件路径");
			return false;
		}
		formData.append('name', name);
		formData.append('type', type);
		formData.append('sex', sex);
		formData.append('remark', remark);
		formData.append('phone', phone);
		formData.append('fileName', $("#fileName").val());
		formData.append('file', $('#filePath')[0].files[0]);
		$.ajax({
			processData: false,
			contentType: false,
			cache : false,
			type : "POST",
			url : ctx + "user/pet/applyfost",
			data :formData,
			async : false,
			error : function(request) {
				$.modal.alertError("系统错误");
			},
			success : function(data) {
				$.modal.alertSuccess("申请成功，请耐心等待工作人员处理,您可在我的寄养申请里查看处理进度");
			}
		});
	}
</script>
</body>
</html>
